import axios from "axios"

export const request = axios.create({
    baseURL: '/dev-api',
    timeout: 5000
})


function loadToken(){
    if(sessionStorage.getItem("token")){
        return sessionStorage.getItem("token")
    }else{
        return localStorage.getItem("token")
    }
}

//响应拦截器
request.interceptors.response.use(config =>config.data)

//请求拦截器
request.interceptors.request.use(req=>{
    const token = loadToken()
    if(token){
        req.headers["Authorization"] = `Bearer ${token}`
    }
    return req;
})





